#include "algorithm.h"

#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>

int Test2() {

  std::string s1;
  int num;
  std::getline(std::cin, s1);
  std::cin >> num;

  std::vector<int> vec;
  int size = s1.size();
  int j = 0;

  std::cout << s1 << std::endl;
  for (int i = 0; i < size; i++) {
    if (s1[i] == ' ' || s1[i] == '\t') {
      int temp = atoi(s1.data() + j);
      vec.push_back(temp);
      std::cout << vec.back() << '\t';
      j = i + 1;
    }
  }
  if (j != size) {
    int temp = atoi(s1.data() + j);
    vec.push_back(temp);
  }
  int vec_size = vec.size();
  for (int i = 0; i < vec_size; i++) {
    if (vec[i] >= num) {
      std::cout << i+1 << std::endl;
      return 0;
    }
  }

  std::cout << vec_size+1 << std::endl;
  return 0;

}


enum Type {
  Digit = 0,
  Negative = 1,
  Other = 2
};

inline Type GetCharType(char c) {
  if (c == '-')
    return Negative;
  else if (c >= '0' && c <= '9')
    return Digit;
  else
    return Other;
}




int Test3() {
  std::string s1;
  std::getline(std::cin, s1);
  int size = s1.size();

  int total = 0;
  bool isNegative = false;
  for (int i = 0; i < size; i++) {
    Type type = GetCharType(s1[i]);
    if (!isNegative) {
      if (type == Digit)
        total += s1[i] - '0';
    }
    if (type == Negative) {
      total += atoi(s1.data() + i);
      isNegative = true;
    }
    if(type == Other)
      isNegative = false;
  }

  std::cout << total << std::endl;
  return 0;
}


enum Status: int32_t {
  Succeed = 0,
  LackL = 1,
  LackO = 2,
  LackX = 4,
};

struct Index {
  int begin = 0; 
  int end = 0;
  bool operator < (const Index& other) const {
    if (begin < other.begin)
      return true;
    else if (begin == other.begin && end < other.end)
      return true;
    return false;
  }
};

void CharStatus(int& s, char c) {
  switch (c)
  {
  case 'l':
    s ^= (int)LackL;
    break;
  case 'o':
    s ^= (int)LackO;
    break;
  case 'x':
    s ^= (int)LackX;
    break;
  }
}


int Test4() {
  std::string s1;
  std::getline(std::cin, s1);
  int size = s1.size();

  std::map<Index, int> results;
  int max_len = 0;
  if (size == 0) {
    std::cout << max_len << std::endl;
    return 0;
  }

  int status0 = 0;
  CharStatus(status0, s1[0]);
  if (status0 != Succeed)
    max_len = 0;
  else
    max_len = 1;

  if (size == 1) {
    std::cout << max_len << std::endl;
    return 0;
  }

  results[{0, 0}] = status0;

  for (int i = 0; i < size - 1; i++) {
    for (int j = i + 1; j < size + i; j++) {
      int status = results[{i, (j - 1)%size}];
      CharStatus(status, s1[j%size]);
      results[{i, j%size}] = status;

      if (status == Succeed && max_len < j - i + 1)
        max_len = j - i + 1;
    }
  }

  int total_status = results[{0, size - 1}];
  if (total_status == size) {
    std::cout << size - 1 << std::endl;
    return 0;
  }

  for (int i = 0; i < size; i++) {
    int temp = total_status;
    CharStatus(temp, s1[i]);
    if (temp == Succeed) {
      std::cout << size - 1 << std::endl;
      return 0;
    }
  }

  if (size - max_len > 2) {
    for (int k = 1; k < size - max_len - 1; k++) {
      for (int i = k; i < size - k; i++) {
        int temp1 = total_status;
        int temp2 = results[{i, i + k}];
        int temp3 = results[{i, (i + size - k) % size}];
        if (((temp1 ^ temp2) == (int)Succeed) || ((temp1 ^ temp3) == (int)Succeed)) {
          std::cout << size - k - 1 << std::endl;
          return 0;
        }
      }
    }
  }

  std::cout << max_len << std::endl;
  return 0;

}


int Correct() {
  std::string s1;
  std::getline(std::cin, s1);
  int size = s1.size();

  std::map<Index, int> results;
  int max_len = 0;
  if (size == 0) {
    std::cout << max_len << std::endl;
    return 0;
  }

  int status0 = 0;
  CharStatus(status0, s1[0]);
  if (status0 != Succeed)
    max_len = 0;
  else
    max_len = 1;

  if (size == 1) {
    std::cout << max_len << std::endl;
    return 0;
  }

  results[{0, 0}] = status0;

  for (int i = 0; i < size - 1; i++) {
    for (int j = i + 1; j < size; j++) {
      int status = results[{i, j - 1}];
      CharStatus(status, s1[j]);
      results[{i, j}] = status;

      if (status == Succeed && max_len < j - i + 1)
        max_len = j - i + 1;
    }
  }

  if (max_len == size) {
    std::cout << size << std::endl;
    return 0;
  }

  int total_status = results[{0, size - 1}];
  for (int i = 0; i < size; i++) {
    int temp = total_status;
    CharStatus(temp, s1[i]);
    if (temp == Succeed) {
      std::cout << size - 1 << std::endl;
      return 0;
    }
  }

  if (size > max_len + 2) {
    for (int k = 1; k < size - max_len - 1; k++) {
      for (int i = 0; i < size - k; i++) {
        int temp1 = total_status;
        int temp2 = results[{i, i + k}];
        if (temp1 == temp2) {
          std::cout << size - k - 1 << std::endl;
          return 0;
        }
      }
    }
  }

  std::cout << max_len << std::endl;
  return 0;

}


TEST(GTest2, GTest2) {
  GTEST_SKIP();
  Test2();
}

TEST(GTest3, GTest3) {
  GTEST_SKIP();
  Test3();
}

TEST(GTest4, GTest4) {
  GTEST_SKIP();
  Test4();
}

